<?php

	class GP_page_sampling_dispatcher extends GP_controleur
	{
		var $controleur;
		var $db;
		var $translation;
		
		function __construct()
		{
			global $page;
			$this -> controleur = parent::getInstance($page);
		}
		
		function controle($id)
		{
			$q = "SELECT id FROM _fo_samples_by_country WHERE id_sample = $id && differential > 0";
			$res = $this -> db -> fetchArray($q);
			if (count($res))
				return true;
			return false;
		}
		
		function afficher()
		{			
			global $page, $urirw;
			if (strlen($urirw))
			{
				$pagerw = fakeurl($urirw);
				$htmltmp = $this -> controleur -> htmlrw('header');
				$htmltmp .= $this -> controleur -> htmlrw($page);
				$htmltmp .= $this -> controleur -> htmlrw('footer');
				savefile($pagerw, $htmltmp);
				if (!IS_IE)
					header("HTTP/1.1 301 Moved Permanently");
				include($urirw);
			}
			else
			{
				$this -> controleur -> add_html('header');
				$this -> controleur -> add_html($page);
				$this -> controleur -> add_html('footer');
			}
		}
		
		function setvar($var, $val)
		{
			global $urirw;
			if (strlen($urirw))
				$this -> $var = $val;
			else
				$this -> controleur -> $var = $val;
		}
	}
	
	$page_sampling_dispatcher = new GP_page_sampling_dispatcher;
	
	// translation id_product => id_sample
	$samples = array(
		4,
		7
	);
	$translation = array(
		7 => 1,
		4 => 2
	);
	
	$page_sampling_dispatcher -> translation = $translation;
	$page_sampling_dispatcher -> db = GP_db::getInstance(BDD_DSN, BDD_UTILISATEUR, BDD_MOT_DE_PASSE);
	
	$ww = $page_sampling_dispatcher -> controle(1);
	$cdg2 = $page_sampling_dispatcher -> controle(2);
	
	if (!$cdg2 && !$ww)
		header('Location: ' . URL_SITE . 'free-sample-perfume/none/apologies/');
	
	
	$page_sampling_dispatcher -> setvar('cdg2', $cdg2);
	$page_sampling_dispatcher -> setvar('ww', $ww);
	$page_sampling_dispatcher -> setvar('titre', 'Our free perfume samples to test fragrances by Comme des Garcons');
	$page_sampling_dispatcher -> setvar('meta_keywords', 'perfume free samples, men, women, test perfume, on line, comme des garcons');
	$page_sampling_dispatcher -> setvar('meta_description', 'Comme des Garcons offers you free perfume samples to test 2 nice eau de perfume : Wonderwood and Comme des Garcons 2');
	$page_sampling_dispatcher -> afficher();
?>